<ui:composition 
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui"
	template="/templates/layout.xhtml">
	
	<ui:param name="worklogsPage" value="true" />
	<ui:define name="content">
	<h:outputStylesheet name="css/main.css" />
	
		<h:form id="wklgForm">
			
			<p:growl id="msgs" showDetail="true"/>
			
			<h:panelGrid styleClass="top-control-panels" columns="3" columnClasses="top-left-panel panel, top-center-panel panel, top-right-panel panel">
				<h:panelGroup>
					<p:outputLabel value="Project:"/><br/>
					<p:selectOneMenu id="project" value="#{worklogBean.currProjectName}" styleClass="item">
						<f:selectItem itemLabel="Select a project" itemValue=""/>
						<f:selectItems value="#{worklogBean.projectList}" var="project" itemLabel="#{project.name}" itemValue="#{project.name}"/>
						<p:ajax update="members issueType issueStatus timeSelection mainButtonsPanel" 
						listener="#{worklogBean.projectChanged}"/>
					</p:selectOneMenu>
					<br/>
					<p:outputLabel value="Members:"/><br />
					<p:selectCheckboxMenu id="members" label="Members" value="#{worklogBean.currAuthors}" disabled="#{worklogBean.disableMenu}" filter="true" filterMatchMode="startsWith" styleClass="item">
						<f:selectItems value="#{worklogBean.authorList}"/>
					</p:selectCheckboxMenu>
				</h:panelGroup>
				
				<h:panelGroup>
					<p:outputLabel value="Issue type:"/><br/>
					<p:selectCheckboxMenu id="issueType" value="#{worklogBean.currIssueType}" disabled="#{worklogBean.disableMenu}" styleClass="item">
						<!-- <f:selectItem itemLabel="All" itemValue=""/> -->
						<f:selectItems value="#{worklogBean.issueTypeList}"/>
					</p:selectCheckboxMenu>
					<br/>
					<p:outputLabel value="Issue status:"/><br/>
					<p:selectCheckboxMenu id="issueStatus" value="#{worklogBean.currIssueStatus}" disabled="#{worklogBean.disableMenu}" styleClass="item">
						<!-- <f:selectItem itemLabel="All" itemValue=""/> -->
						<f:selectItems value="#{worklogBean.issueStatusList}"/>
					</p:selectCheckboxMenu>
				</h:panelGroup>
				
				<h:panelGroup>
				
					<p:outputLabel value="Time:"/><br/>
					
					<p:outputPanel id="timeSelection" styleClass="timeSelection">
						
						<p:selectOneRadio id="timeSelector" value="#{worklogBean.currTimeSelector}" 
						disabled="#{worklogBean.disableMenu}" layout="custom">
							<f:selectItem itemValue="dateList" itemLabel="DateList"/>
							<f:selectItem itemValue="dateCalendar" itemLabel="DateCalendar"/>
							<p:ajax update="predefinedDate fromDate toDate"
							listener="#{worklogBean.timeSelectorChanged}"/>
						</p:selectOneRadio>
						
						<h:panelGrid columns="2" cellpadding="0" cellspacing="0" columnClasses="calendarTable1,calendarTable1">
							<p:radioButton for="timeSelector" itemIndex="0"/>
							<p:selectOneMenu id="predefinedDate" value="#{worklogBean.currPredefinedDate}" 
							disabled="#{worklogBean.disableDateList or worklogBean.disableMenu}">
								<f:selectItems value="#{worklogBean.predefinedDateList}"/>
							</p:selectOneMenu>
						</h:panelGrid>
						
						<p:outputLabel value="SomeText" style="visibility: hidden"/>
						
						<h:panelGrid columns="5" cellpadding="0" cellspacing="0" columnClasses="calendarTable1,calendarTable2,calendarTable1,calendarTable2,calendarTable1">
							<p:radioButton for="timeSelector" itemIndex="1"/>
							<p:outputLabel value="From:"/>
							<p:calendar id="fromDate" value="#{worklogBean.calendarFromDate}" size="4" 
							disabled="#{!worklogBean.disableDateList or worklogBean.disableMenu}"/>
							<p:outputLabel value="To:"/>
							<p:calendar id="toDate" value="#{worklogBean.calendarToDate}" size="4" 
							disabled="#{!worklogBean.disableDateList or worklogBean.disableMenu}"/>
						</h:panelGrid>
						
					</p:outputPanel>
				
				</h:panelGroup>
			</h:panelGrid>
			
			<h:panelGrid styleClass="main-buttons-panel panel" id="mainButtonsPanel">
				<h:panelGroup>
					<p:commandButton value="Show" styleClass="main-buttons"
					actionListener="#{worklogBean.showButtonClick}" update="tabs:worklogList tabs:byUserList tabs:byComponentList tabs:btTypeList msgs"
					disabled="#{worklogBean.disableMenu}"/>
					
					<p:commandButton value="Clear" styleClass="main-buttons"
					actionListener="#{worklogBean.clearButtonClick}" update="tabs:worklogList tabs:byUserList tabs:byComponentList tabs:btTypeList msgs"
					disabled="#{worklogBean.disableMenu}"/>
					
					<p:commandButton value="Update" styleClass="main-buttons" ajax="false"
					actionListener="#{worklogBean.updateButtonClick}"
					disabled="#{worklogBean.disableMenu}"/>
				</h:panelGroup>
			</h:panelGrid>
			
			<p:tabView id="tabs" styleClass="tabView">
			<p:tab title="All Worklogs">
				
				<p:dataTable id="worklogList" value="#{worklogBean.worklogList}" var="worklog" rowIndexVar="rowIndex">
					<f:facet name="header">
						<h:outputText value="Total Time Spent (h:mm)"/><br/>
						<h:outputText value="#{worklogBean.totalTimeSpent}" converter="com.jastt.frontend.beans.worklog.IntToHMConverter"/>
						
						<div class="top-export-buttons-panel">
							<h:commandButton  actionListener="#{worklogBean.exportWorklogReport}"  image="/resources/img/pdf32.png" styleClass="export-button" title="Issue report PDF">
								<f:param name="reportFormat" value="pdf"/>
							</h:commandButton>
							<h:commandButton  actionListener="#{worklogBean.exportWorklogReport}"  image="/resources/img/xls32.png" styleClass="export-button" title="Issue report XLS">
								<f:param name="reportFormat" value="xls"/>
							</h:commandButton>
							<h:commandButton actionListener="#{worklogBean.exportWorklogReport}" image="/resources/img/xlsx32.png" styleClass="export-button" title="Issue report XLSX">
								<f:param name="reportFormat" value="xlsx"/>
							</h:commandButton>
						</div>
						
					</f:facet>
					
					<p:column headerText="№">
						<h:outputText value="#{rowIndex+1}"/>
					</p:column>
					<p:column headerText="Created" sortBy="#{worklog.started}">
						<h:outputText value="#{worklog.started}">
							<f:convertDateTime pattern="dd.MM.yyyy"/>
						</h:outputText>
					</p:column>
					<p:column headerText="Due Date" sortBy="#{worklog.issue.due}">
						<h:outputText value="#{worklog.issue.due}">
							<f:convertDateTime pattern="dd.MM.yyyy"/>
						</h:outputText>
					</p:column>
					<p:column headerText="Resolved" sortBy="#{worklog.issue.resolved}">
						<h:outputText value="#{worklog.issue.resolved}">
							<f:convertDateTime pattern="dd.MM.yyyy"/>
						</h:outputText>
					</p:column>
					<p:column headerText="Member" sortBy="#{worklog.author}">
						<h:outputText value="#{worklog.author}"/>
					</p:column>		
					
					<p:column headerText="Issue Key" sortBy="#{worklog.issue.key}" sortFunction="#{reportBean.sortInNaturalOrder}">
						<h:outputLink value="#{worklog.issue.url}" target="blank" styleClass="out-link">
							#{worklog.issue.key}
						</h:outputLink>
					</p:column>
					
					<p:column headerText="Issue Type" sortBy="#{worklog.issue.issueType}">
						<h:outputText value="#{worklog.issue.issueType}"/>
					</p:column>
					<p:column headerText="Issue Status" sortBy="#{worklog.issue.status}">
						<h:outputText value="#{worklog.issue.status}"/>
					</p:column>
					
					<p:column headerText="Issue Summary" sortBy="#{worklog.issue.summary}">
						<h:outputLink value="#{worklog.issue.url}" target="blank" styleClass="out-link">
							#{worklog.issue.summary}
						</h:outputLink>
					</p:column>
					
					<p:column headerText="Spent (h:mm)" sortBy="#{worklog.timeSpent}">
						<h:outputText  value="#{worklog.timeSpent}" converter="com.jastt.frontend.beans.worklog.IntToHMConverter"/>
					</p:column>
				</p:dataTable>
			
			</p:tab>
			
			<p:tab title="By User">
				
				<p:dataTable id="byUserList" value="#{worklogBean.byUserReportList}" var="report" rowIndexVar="rowIndex">
					<f:facet name="header">
						<h:outputText value="Total Time Spent (h:mm)"/><br/>
						<h:outputText value="#{worklogBean.totalTimeSpent}" converter="com.jastt.frontend.beans.worklog.IntToHMConverter"/>
						
						<div class="top-export-buttons-panel">
							<h:commandButton  actionListener="#{worklogBean.exportWorklogReport}"  image="/resources/img/pdf32.png" styleClass="export-button" title="Issue report PDF">
								<f:param name="reportFormat" value="pdf"/>
							</h:commandButton>
							<h:commandButton  actionListener="#{worklogBean.exportWorklogReport}"  image="/resources/img/xls32.png" styleClass="export-button" title="Issue report XLS">
								<f:param name="reportFormat" value="xls"/>
							</h:commandButton>
							<h:commandButton actionListener="#{worklogBean.exportWorklogReport}" image="/resources/img/xlsx32.png" styleClass="export-button" title="Issue report XLSX">
								<f:param name="reportFormat" value="xlsx"/>
							</h:commandButton>
						</div>
						
					</f:facet>
					
					<p:column>
       					<p:rowToggler />
   					</p:column>
   					<p:column headerText="№">
						<h:outputText value="#{rowIndex+1}"/>
					</p:column>
					<p:column headerText="Member" sortBy="#{report.author}">
						<h:outputText value="#{report.author}"/>
					</p:column>
					<p:column headerText="Spent (h:mm)" sortBy="#{report.totalTimeSpent}">
						<h:outputText  value="#{report.totalTimeSpent}" converter="com.jastt.frontend.beans.worklog.IntToHMConverter"/>
					</p:column>
					<p:column headerText="Actuality (%)" sortBy="#{report.actuality}">
						<h:outputText  value="#{report.actuality}"/>
					</p:column>
					
					<p:rowExpansion>
						
						<p:dataTable value="#{report.worklogs}" var="worklog" rowIndexVar="rowIndex">
							<p:column headerText="№">
								<h:outputText value="#{rowIndex+1}"/>
							</p:column>
							<p:column headerText="Date" sortBy="#{worklog.started}">
								<h:outputText value="#{worklog.started}">
									<f:convertDateTime pattern="dd/MM/yyyy HH:mm"/>
								</h:outputText>
							</p:column>	
							
							<p:column headerText="Issue Key" sortBy="#{worklog.issue.key}" sortFunction="#{reportBean.sortInNaturalOrder}">
								<h:outputLink value="#{worklog.issue.url}" target="blank" styleClass="out-link">
									#{worklog.issue.key}
								</h:outputLink>
							</p:column>
							
							<p:column headerText="Issue Type" sortBy="#{worklog.issue.issueType}">
								<h:outputText value="#{worklog.issue.issueType}"/>
							</p:column>
							<p:column headerText="Issue Status" sortBy="#{worklog.issue.status}">
								<h:outputText value="#{worklog.issue.status}"/>
							</p:column>
							
							<p:column headerText="Issue Summary" sortBy="#{worklog.issue.summary}">
								<h:outputLink value="#{worklog.issue.url}" target="blank" styleClass="out-link">
									#{worklog.issue.summary}
								</h:outputLink>
							</p:column>
							
							<p:column headerText="Spent (h:mm)" sortBy="#{worklog.timeSpent}">
								<h:outputText  value="#{worklog.timeSpent}" converter="com.jastt.frontend.beans.worklog.IntToHMConverter"/>
							</p:column>
						</p:dataTable>
						
					</p:rowExpansion>
					
				</p:dataTable>
				
			</p:tab>
			<p:tab title="By Component">
				
				<p:dataTable id="byComponentList" value="#{worklogBean.byComponentReportList}" var="report" rowIndexVar="rowIndex">
					<f:facet name="header">
						<h:outputText value="Total Time Spent (h:mm)"/><br/>
						<h:outputText value="#{worklogBean.totalTimeSpent}" converter="com.jastt.frontend.beans.worklog.IntToHMConverter"/>
						
						<div class="top-export-buttons-panel">
							<h:commandButton  actionListener="#{worklogBean.exportWorklogReport}"  image="/resources/img/pdf32.png" styleClass="export-button" title="Issue report PDF">
								<f:param name="reportFormat" value="pdf"/>
							</h:commandButton>
							<h:commandButton  actionListener="#{worklogBean.exportWorklogReport}"  image="/resources/img/xls32.png" styleClass="export-button" title="Issue report XLS">
								<f:param name="reportFormat" value="xls"/>
							</h:commandButton>
							<h:commandButton actionListener="#{worklogBean.exportWorklogReport}" image="/resources/img/xlsx32.png" styleClass="export-button" title="Issue report XLSX">
								<f:param name="reportFormat" value="xlsx"/>
							</h:commandButton>
						</div>
						
					</f:facet>
					
					<p:column>
       					<p:rowToggler />
   					</p:column>
   					<p:column headerText="№">
						<h:outputText value="#{rowIndex+1}"/>
					</p:column>
					<p:column headerText="Member" sortBy="#{report.author}">
						<h:outputText value="#{report.author}"/>
					</p:column>
					<p:column headerText="Spent (h:mm)" sortBy="#{report.totalTimeSpent}">
						<h:outputText  value="#{report.totalTimeSpent}" converter="com.jastt.frontend.beans.worklog.IntToHMConverter"/>
					</p:column>
					<p:column headerText="Actuality (%)" sortBy="#{report.actuality}">
						<h:outputText  value="#{report.actuality}"/>
					</p:column>
					
					<p:rowExpansion>
						
						<p:dataTable value="#{report.worklogs}" var="worklog" rowIndexVar="rowIndex">
							<p:column headerText="№">
								<h:outputText value="#{rowIndex+1}"/>
							</p:column>
							<p:column headerText="Date" sortBy="#{worklog.started}">
								<h:outputText value="#{worklog.started}">
									<f:convertDateTime pattern="dd/MM/yyyy HH:mm"/>
								</h:outputText>
							</p:column>	
							
							<p:column headerText="Issue Key" sortBy="#{worklog.issue.key}" sortFunction="#{reportBean.sortInNaturalOrder}">
								<h:outputLink value="#{worklog.issue.url}" target="blank" styleClass="out-link">
									#{worklog.issue.key}
								</h:outputLink>
							</p:column>
							
							<p:column headerText="Worklog Author" sortBy="#{worklog.author}">
								<h:outputText value="#{worklog.author}"/>
							</p:column>
							<p:column headerText="Issue Status" sortBy="#{worklog.issue.status}">
								<h:outputText value="#{worklog.issue.status}"/>
							</p:column>
							
							<p:column headerText="Issue Summary" sortBy="#{worklog.issue.summary}">
								<h:outputLink value="#{worklog.issue.url}" target="blank" styleClass="out-link">
									#{worklog.issue.summary}
								</h:outputLink>
							</p:column>
							
							<p:column headerText="Spent (h:mm)" sortBy="#{worklog.timeSpent}">
								<h:outputText  value="#{worklog.timeSpent}" converter="com.jastt.frontend.beans.worklog.IntToHMConverter"/>
							</p:column>
						</p:dataTable>
						
					</p:rowExpansion>
					
				</p:dataTable>
				
			</p:tab>
			<p:tab title="By Type">
				
				<p:dataTable id="btTypeList" value="#{worklogBean.byTypeReportList}" var="report" rowIndexVar="rowIndex">
					<f:facet name="header">
						<h:outputText value="Total Time Spent (h:mm)"/><br/>
						<h:outputText value="#{worklogBean.totalTimeSpent}" converter="com.jastt.frontend.beans.worklog.IntToHMConverter"/>
						
						<div class="top-export-buttons-panel">
							<h:commandButton  actionListener="#{worklogBean.exportWorklogReport}"  image="/resources/img/pdf32.png" styleClass="export-button" title="Issue report PDF">
								<f:param name="reportFormat" value="pdf"/>
							</h:commandButton>
							<h:commandButton  actionListener="#{worklogBean.exportWorklogReport}"  image="/resources/img/xls32.png" styleClass="export-button" title="Issue report XLS">
								<f:param name="reportFormat" value="xls"/>
							</h:commandButton>
							<h:commandButton actionListener="#{worklogBean.exportWorklogReport}" image="/resources/img/xlsx32.png" styleClass="export-button" title="Issue report XLSX">
								<f:param name="reportFormat" value="xlsx"/>
							</h:commandButton>
						</div>
						
					</f:facet>
					
					<p:column>
       					<p:rowToggler />
   					</p:column>
   					<p:column headerText="№">
						<h:outputText value="#{rowIndex+1}"/>
					</p:column>
					<p:column headerText="Member" sortBy="#{report.author}">
						<h:outputText value="#{report.author}"/>
					</p:column>
					<p:column headerText="Spent (h:mm)" sortBy="#{report.totalTimeSpent}">
						<h:outputText  value="#{report.totalTimeSpent}" converter="com.jastt.frontend.beans.worklog.IntToHMConverter"/>
					</p:column>
					<p:column headerText="Actuality (%)" sortBy="#{report.actuality}">
						<h:outputText  value="#{report.actuality}"/>
					</p:column>
					
					<p:rowExpansion>
						
						<p:dataTable value="#{report.worklogs}" var="worklog" rowIndexVar="rowIndex">
							<p:column headerText="№">
								<h:outputText value="#{rowIndex+1}"/>
							</p:column>
							<p:column headerText="Date" sortBy="#{worklog.started}">
								<h:outputText value="#{worklog.started}">
									<f:convertDateTime pattern="dd/MM/yyyy HH:mm"/>
								</h:outputText>
							</p:column>	
							
							<p:column headerText="Issue Key" sortBy="#{worklog.issue.key}" sortFunction="#{reportBean.sortInNaturalOrder}">
								<h:outputLink value="#{worklog.issue.url}" target="blank" styleClass="out-link">
									#{worklog.issue.key}
								</h:outputLink>
							</p:column>
							
							<p:column headerText="Worklog author" sortBy="#{worklog.author}">
								<h:outputText value="#{worklog.author}"/>
							</p:column>
							<p:column headerText="Issue Status" sortBy="#{worklog.issue.status}">
								<h:outputText value="#{worklog.issue.status}"/>
							</p:column>
							
							<p:column headerText="Issue Summary" sortBy="#{worklog.issue.summary}">
								<h:outputLink value="#{worklog.issue.url}" target="blank" styleClass="out-link">
									#{worklog.issue.summary}
								</h:outputLink>
							</p:column>
							
							<p:column headerText="Spent (h:mm)" sortBy="#{worklog.timeSpent}">
								<h:outputText  value="#{worklog.timeSpent}" converter="com.jastt.frontend.beans.worklog.IntToHMConverter"/>
							</p:column>
						</p:dataTable>
						
					</p:rowExpansion>
					
				</p:dataTable>
				
			</p:tab>
			</p:tabView>
				
		</h:form>

	</ui:define>
</ui:composition>